package com.garden.web.context.config;

import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

//@Configuration
//@EnableMongoRepositories(basePackages = "com.garden.*.**.model.**")
public class MongoConfig extends AbstractMongoConfiguration {
    @Value("${mongo.host}")
    private String mongoHost;
    @Value("${mongo.port}")
    private int mongoPort;
    @Value("${mongo.db}")
    private String mongoDbName;
    @Value("${mongo.test}")
    private boolean isTest;

    @Bean
    @Override
    public Mongo mongo() throws Exception {
        return new MongoClient(mongoHost, mongoPort);
    }

    @Bean
    @Override
    public MongoTemplate mongoTemplate() throws Exception {
        return new MongoTemplate(mongo(),getDatabaseName());
    }

    @Override
    protected String getDatabaseName() {
        return mongoDbName;
    }

    @Override
    protected Collection<String> getMappingBasePackages() {
        List<String> basePackages = Collections.emptyList();;
        basePackages.add("com.garden.*.**.model.**");
        return basePackages;
    }
}
